<template>
	<mescroll-uni :ref="'mescrollRef'+tabIndex" @init="mescrollInit"   @down="downCallback" @up="upCallback">
		<!-- 数据列表 -->
		<view class="u-padding-left-32 u-padding-right-32">
			<view class="u-margin-top-20" v-for="(item,index) in dataList" :key="index">
				<list-item :item="item.product" :isShare="false" :isTag="false" :showTime="false" :showStar="false">
					<view slot="content">
						<view class="u-font-24 content-desc-item u-margin-top-10">
							<flex-text width="96" txt="申请人" size="24"></flex-text>：{{item.createName || ''}}
						</view>
						<view class="u-font-24 content-desc-item u-margin-top-10">申请类别：{{item.afterType | afterType}}</view>
						<view class="u-font-24 content-desc-item u-margin-top-10 u-flex u-col-top">
							申请原因：<view class="u-flex-1 line-height u-line-3">{{item.content}}</view>
						</view>
						<view class="u-font-24 content-desc-item u-margin-top-10">提交时间：{{item.createTime | timeFormat}}</view>
						<!-- <view class="u-font-24 content-desc-item u-margin-top-10" v-if="item.status!=0">审核时间：{{item.verifyDate | timeFormat}}</view> -->
						<view class="u-flex u-flex-wrap">
							<view v-for="(img,i) in item.image" :key="i" class="u-padding-right-6 u-margin-top-12" @click="preview(img,item.image)">
								<item-image  :img="img" :width="122" :height="122" />
							</view>
						</view>
					</view>
					<view slot="footer"></view>
					<view slot="end">
						<view class="u-flex u-row-between u-margin-top-20" v-if="loginForm.userType==='issue'&&item.status==0"> 
							<view>
								<item-btn  type="plain" @click="commit(item,2)" :loading="commitFlag" width="290" height="64">
									<text class="content-desc-item u-font-24">驳回</text>
								</item-btn>
							</view>
							<view>
								<item-btn @click="commit(item,1)" :loading="commitFlag" width="290" height="64">
									<text class="text-white u-font-24">通过</text>
								</item-btn>
							</view>
						</view>
						<view class="u-flex u-margin-top-20 u-margin-bottom-20 u-row-right" 
							v-if="item.creatorId==loginForm.uid&&loginForm.userType!=='issue' || item.status!=0">
							<text class="u-margin-right-12 u-font-24 content-desc-item text-bold">{{item.statusName}}</text>
							<u-icon :name="item.statusIcon" :color="currentThemeObj.primary" size="37" v-if="item.status!=0"></u-icon>
						</view>
						<!-- <view class="u-font-24 content-desc-item u-margin-top-10 u-flex u-row-right" v-if="item.rejectReason">
							<view>
								<text class="text-color-txtTheme line-height">驳回理由：</text>{{item.rejectReason}}
							</view>
						</view> -->
					</view>
				</list-item>
			</view>
		</view>
	</mescroll-uni>
</template>

<script>
	import upCallback from '@/mixins/upCallbackMixin.js'
	import data from '@/data/index.js'
	import { customRequest} from '@/api/crud.js'
	export default {
		mixins: [upCallback], 
		props:{
			form:{
				type:Object,
				default:()=>({})
			},
			tabIndex:{
				type:Number,
				default:0
			}
		},
		data() {
			return {
				apiModule:'shopApi',
				apiType:'storeOrderAfterSale',
				dataList:[],
				commitFlag:false
			}
		},
		methods: {
			dataListCallBack(){
				this.dataList = this.dataList.map(val=>{
					if(typeof val.image==='string') val.image = val.image ? val.image.split(',') : [];
					val.statusName = ['审核中','已退款','未通过'][val.status];
					val.statusIcon = ['close-circle-fill','checkmark-circle-fill','close-circle-fill'][val.status];
					return val
				})
			},
			commit(item,flag){
				const obj = {
					id:item.id,
					status:flag
				}
				if(flag==2) obj.rejectReason = '驳回申请'
				this.verify(obj)
			},
			verify(form){
				this.commitFlag = true;
				customRequest(form,this.apiType,this.apiModule,'verify').then(res=>{
					this.$u.toast('审核成功')
					this.commitFlag = false;
					this.downCallback()
				}).catch(()=>{
					this.commitFlag = false;
				})
			},
			preview(current,urls){
				this.previewUrls(urls,current)
			}
		},
		filters:{
			afterType(val){
				const obj = data.afterTypeList.find(item=>item.value==val);
				if(!obj) return false;
				return obj.label
			}
		}
	}
</script>

<style lang="scss" scoped>
	.right-content{
		flex-direction: column;
		display: flex;
		height: 166rpx;
		margin-left: 24rpx;
	}
	.line-height{
		line-height: 30rpx;
	}
</style>

 